package com.example.a02back.controller;


import com.example.a02back.common.APIResponse;
import com.example.a02back.service.impl.AuthServicelmpl;
import com.example.a02back.service.impl.ChatRoomServiceImpl;
import com.example.a02back.service.impl.MessageServiceImpl;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author SimpChaos
 * @since 2022-07-02
 */
@RestController
@Controller
@ResponseBody
@RequestMapping("/message")
public class MessageController {

    @Resource
    private AuthServicelmpl auth;
    @Resource
    private MessageServiceImpl messageService;
    @Resource
    private ChatRoomServiceImpl chatRoomService;

    /**
     * @Description: 
     * @Author: SimpChaos 
     * @Date: 2022/7/21 7:18
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("/start")
    public APIResponse<?> start(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String uid = httpServletRequest.getParameter("uid");
        String swapper = httpServletRequest.getParameter("swapper");
        String sid = httpServletRequest.getParameter("sid");
        return APIResponse.success("SUCCESS",chatRoomService.start(uid,swapper,sid));
    }



    /**
     * @Description:
     * @Author: SimpChaos
     * @Date: 2022/7/20 16:50
     * @Param:
     * @Return:
     */
    @CrossOrigin
    @RequestMapping("/send")
    public APIResponse<?> send(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String token = httpServletRequest.getHeader("Token");
        String send = httpServletRequest.getParameter("send");
        String receive = httpServletRequest.getParameter("receive");
        String content = httpServletRequest.getParameter("content");
        String roomId = httpServletRequest.getParameter("roomid");

        return APIResponse.success("SUCCESS",messageService.send(token,send,receive,content,roomId));
    }


    /**
     * @Description: 
     * @Author: SimpChaos 
     * @Date: 2022/7/21 7:42
     * @Param: [httpServletRequest, httpServletResponse]
     * @Return: com.example.a02back.common.APIResponse<?>
     */
    @CrossOrigin
    @RequestMapping("/receive")
    public APIResponse<?> receive(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse){
        String send = httpServletRequest.getParameter("send");
        String receive = httpServletRequest.getParameter("receive");
        String roomid = httpServletRequest.getParameter("roomid");
        return APIResponse.success("success",messageService.receive(send,receive,roomid));
    }




}
